package com.java.jvm.heap;
import java.util.concurrent.TimeUnit;

/**实例内部导致的内存泄漏问题*/
class OuterClass {
    //实例内部类，实例内部类会默认保存外部类应用
    class InnerClass { }
    //静态内部类默认不会保存外部类引用
    static class StaticInnerClass{ }
    //finalize方法会在对象销毁之前进行调用，重写的目的是判断对象是否要销毁了
    @Override
    protected void finalize() throws Throwable {
        System.out.println("==finalize()==");
    }
}
public class InnerLeakTests {
    public static void main(String[] args) throws InterruptedException {
        OuterClass outer=new OuterClass();
        //OuterClass.InnerClass inner1= outer.new InnerClass();
        OuterClass.StaticInnerClass inner2=new OuterClass.StaticInnerClass();
        outer=null;
        //手动gc
        System.gc();
    }
}
